<?php

namespace app\service;

use app\model\NotesInfoModel;
use share\service\BaseModelService;

class NotesInfoService extends BaseModelService
{

    public static function getModel(){
        return new NotesInfoModel;
    }

    public static function addNotes($data,$vendor,$appVersion)
    {
        $item = [
            'contact_way' => $data['contactWay'],
            'contact_type' => isset($data['contactType']) ? $data['contactType'] : '',
            'notes' => $data['notes'],
            'vendor' => $vendor,
            'app_version' => $appVersion,
        ];
        $res = self::add($item);
        return NotesInfoModel::formatModelData($res);
    }

    public static function buildCondition($filter){
        $res = [];
        if(isset($filter['contactWay']) && !empty($filter['contactWay'])){
            $res['contact_way'] = $filter['contactWay'];
        }
        if(isset($filter['notes']) && !empty($filter['notes'])){
            $res['notes'] = ['like','%'. $filter['notes'].'%'];
        }
        if(isset($filter['appVersion']) && !empty($filter['appVersion'])){
            $res['app_version'] = $filter['appVersion'];
        }   
        return $res;
    } 

}
